package com.base.component.ai.workflow.utils;

import java.util.HashMap;
import java.util.Map;

import org.springframework.util.CollectionUtils;

public class FlowUtils {

	/**
	 * 参数转换,${}，需替换变量
	 * @param contextParams
	 * @param resultParams
	 * @return
	 */
	public static Map<String,Object> paramConverMap(Map<String,Object> contextParams,
			Map<String,String> resultParams){
		Map<String,Object> result=new HashMap<>();
		if(!CollectionUtils.isEmpty(resultParams)) {
			for(String key:resultParams.keySet()) {
				String value=resultParams.get(key);
				if(value.startsWith("${")&&value.endsWith("}")) {
					String k=value.substring(2,value.length()-1);
					result.put(key, contextParams.get(k));
				}else {
					result.put(key, resultParams.get(key));
				}
			}
		}
		return result;
	}
	
}
